package prickworlds.game;

import prickworlds.Prickworlds;
import prickworlds.game.templates.RobotTemplate;

/**
 * Player class
 * 
 * @author Nicolas Winkler
 * @author Christian Holzreuter
 * 
 */
public class Player extends Robot {
	public Player(RobotTemplate template) {
		super(template);
	}

	/**
	 * current experience
	 */
	float exp;

	/**
	 * current score
	 */
	int score = 0;

	/**
	 * 
	 * @param up
	 *            if the up button is pressed
	 * @param down
	 *            if the down button is pressed
	 * @param left
	 *            if the left button is pressed
	 * @param right
	 *            if the right button is pressed
	 */
	public void update(boolean up, boolean down, boolean left, boolean right) {
		if (up) {
			velY = -1.0f;
		} else if (down) {
			velY = 1.0f;
		} else {
			velY = 0.0f;
		}
		if (left) {
			velX = -1.0f;
		} else if (right) {
			velX = 1.0f;
		} else {
			velX = 0.0f;
		}
		if (velX != 0.0f || velY != 0.0f) {
			float shortener = 0.01f / (float) Math.sqrt(velX * velX + velY
					* velY);
			velX *= shortener * template.getMaxSpeed();
			velY *= shortener * template.getMaxSpeed();
		}
		super.update();
	}

	public void requestShot() {
		targetX = Prickworlds.getGame().getMouseX();
		targetY = Prickworlds.getGame().getMouseY();
		targetX = Prickworlds.getGame().screenToMapX(targetX);
		targetY = Prickworlds.getGame().screenToMapY(targetY);
		super.requestShot();
	}
}
